package weixintest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/4/10 15:33
 */
public class MyTest {
    static int a = 0;
    static int b = 0;
    static AtomicInteger atomicInt = new AtomicInteger(0);

    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();

        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    a += 1;
                    b++;
                    atomicInt.incrementAndGet();
                }
            });

            exec.execute(t);
        }

        exec.shutdown();

        System.out.println("a+=1在多线程下的结果:" + a);
        System.out.println("b++在多线程下的结果：" + b);
        System.out.println("原子类在多线程下的结果" + atomicInt.get());
    }
}
